package org.javaside.giveme.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import weibo4j.http.AccessToken;

/**
 * 处理用户是否有权限访问资源处理器
 * 
 * @author xiaozhou
 * 
 */
public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
	Logger logger = LoggerFactory.getLogger(getClass());
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		AccessToken sinaAccessToken = (AccessToken)request.getSession().getAttribute("accessToken");
		com.tencent.weibo.beans.OAuth ttAccessToken = (com.tencent.weibo.beans.OAuth)request.getSession().getAttribute("ttAccessToken");
		
		if(sinaAccessToken==null && ttAccessToken==null){
			response.sendRedirect(request.getContextPath()+"/?status=nologin");
			return false;
		}
		return true;
	}
}
